package com.lin.views;

import com.yunfeng.supercall.R;

import android.content.Context;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;


/**
 * 加载动画管理类
 * 
 * @author kapai8
 * 
 */
public class AnimationManger {
	public static final String TAG = "tag";
	public static Context mContext;
	public static Animation mAnimation;

	/**
	 * 加载动画
	 */
	public static synchronized Animation getAnimation(Context mContext) {
		if (AnimationManger.mContext == mContext && mAnimation != null) {
			return mAnimation;
		} else {
			try {

				mAnimation = AnimationUtils.loadAnimation(mContext,
						R.anim.loading_animation);
				AnimationManger.mContext = mContext;
			} catch(Exception e) {

			}
		}

		return mAnimation;
	}

	/**
	 * 停止加载动画
	 */
	public static void stopAnimation(View mLayoutView,
			ImageView mLoadingImageView) {
		mLayoutView.setVisibility(View.VISIBLE);
		mLoadingImageView.setVisibility(View.GONE);
		mLoadingImageView.clearAnimation();
	}

	/**
	 * 播放加载动画
	 */
	public static void startAnimation(View mLayoutView,
			ImageView mLoadingImageView, Context mContext) {
		mLayoutView.setVisibility(View.GONE);
		mLoadingImageView.setVisibility(View.VISIBLE);
		mLoadingImageView.startAnimation(getAnimation(mContext));
	}

	/**
	 * 启动加载动画
	 */
	public static void startAnimation(ImageView mLoadingImageView,
			Context mContext) {
		mLoadingImageView.setVisibility(View.VISIBLE);
		mLoadingImageView.startAnimation(getAnimation(mContext));
	}

	/**
	 * 取消加载动画
	 */
	public static void stopAnimation(ImageView mLoadingImageView) {
		if(mLoadingImageView == null){
			return;
		}
		mLoadingImageView.setVisibility(View.GONE);
		mLoadingImageView.clearAnimation();
	}
}
